package cn.devkits.utils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.log4j.Logger;

import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;

/**
 * 系统工具类
 *
 * @author liushaofeng
 * @DateTime 2018年7月17日 下午9:45:02
 * @Version 1.0.0.0
 */
public final class DKSystemUtils {

	private static final Properties versionProperties = new Properties();
	private static final Properties systemCfg = new Properties();
	private static final StringBuilder openSourceInfo = new StringBuilder();

	/**
	 * 初始化系统参数/数据
	 */
	public static void init() {
		try {
			versionProperties.load(DKSystemUtils.class.getClassLoader().getResourceAsStream("version.ini"));
			systemCfg.load(DKSystemUtils.class.getClassLoader().getResourceAsStream("cfg/devkits.cfg"));
		} catch (FileNotFoundException e) {
			Logger.getLogger(DKSystemUtils.class).error(e.getMessage(), e);
		} catch (IOException e) {
			Logger.getLogger(DKSystemUtils.class).error(e.getMessage(), e);
		}

		try {
			InputStream resourceAsStream = DKSystemUtils.class.getClassLoader()
					.getResourceAsStream("cfg/OpenSource.info");
			BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream));
			String line = null;
			while ((line = reader.readLine()) != null) {
				openSourceInfo.append(line + System.getProperty("line.separator"));
			}
		} catch (IOException e) {
			Logger.getLogger(DKSystemUtils.class).error(e.getMessage(), e);
		}
	}

	/**
	 * 获取当前系统的版本号
	 *
	 * @return 当前系统版本号
	 */
	public static final String getCurrentVersion() {
		return versionProperties.getProperty("VERSION");
	}

	/**
	 * 获取代码库版本号
	 *
	 * @return 代码库版本号
	 */
	public static final String getBuildVersion() {
		return versionProperties.getProperty("BUILD");
	}

	/**
	 * 获取开源软件库信息
	 *
	 * @return 开源软件信息
	 */
	public static final String getOpenSourceInfo() {
		return openSourceInfo.toString();
	}

	/**
	 * 获取当前屏幕的尺寸
	 *
	 * @return 当前屏幕的尺寸
	 */
	public static final Rectangle2D getScreenSize() {
		Screen screen = Screen.getPrimary();
		return screen.getVisualBounds();
	}

	/**
	 * 获取用户的配置信息
	 */
	public static final Object getUserCfg() {
		// TODO
		return null;
	}
}
